//
//  linkListSet.swift
//  SetAndMap
//
//  Created by lhc on 2024/7/20.
//

import Foundation

/// 内部是链表的集合
class LinkListSet<E: Comparable>: MySet {
    
    private let linklist = LinkList<E>()
    
    func getSize() -> Int {
        return linklist.getSize()
    }
    
    func isEmpty() -> Bool {
        return linklist.isEmpty()
    }
    
    func add(element: E) {
        if !self.contains(element) {
            linklist.addFirst(element: element)
        }
    }
    
    func contains(_ element: E) -> Bool {
        return linklist.contains(e: element)
    }
    
    func removeElement(_ element: E) {
        linklist.deleteElement(element)
    }
    
}

extension LinkListSet: CustomStringConvertible {
    var description: String {
        return "\(self.linklist.traversalList())"
    }
    
    
}
